package com.ias.agdis_r.terminalmanager.restful.findluggage.service;

import android.text.TextUtils;

import com.ias.agdis_r.manager.FindLuggageDataManager;
import com.ias.agdis_r.module.MessageModel;
import com.ias.agdis_r.terminalmanager.restful.findluggage.endpoint.request.FindLuggageRequest;
import com.ias.agdis_r.terminalmanager.restful.findluggage.endpoint.request.ReportFindLuggageRequest;
import com.ias.agdis_r.terminalmanager.restful.findluggage.vo.FindLuggageInfoRequestVO;
import com.ias.agdis_r.terminalmanager.restful.findluggage.vo.LuggageVO;
import com.ias.agdis_r.terminalmanager.restful.findluggage.vo.ReportFindLuggageRequestVO;
import com.ias.agdis_r.util.S;
import com.ias.agdis_r.util.network.HttpUtil;
import com.ias.agdis_r.util.sdcard.WriteLog;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 翻行李服务
 * Created by zhaowl on 2018/6/5.
 */
public class FindLuggageService {

    /**
     * 获取翻行李信息
     */
    public static void getFindLuggageInfo() {
        Set<String> tnbSet  = FindLuggageDataManager.getInstance().getFindLuggageTnbSet();
        if (tnbSet == null || tnbSet.isEmpty()) {
            return;
        }
        FindLuggageInfoRequestVO findLuggageInfoRequestVO = new FindLuggageInfoRequestVO();
        FindLuggageRequest findLuggageRequest = new FindLuggageRequest();
        List tnbList =new ArrayList<String>(tnbSet);
        WriteLog.getInstance().writeDebugLog("获取翻行李信息-任务号列表"+S.valueOf(tnbList));
        findLuggageInfoRequestVO.setListTNB(tnbList);
        findLuggageRequest.setFindLuggageInfoRequestVO(findLuggageInfoRequestVO);
        HttpUtil.getInstance().sendRequest(findLuggageRequest, MessageModel.FXLI, false);
    }

    /**
     * 上报翻行李状态
     * @param tnb 任务号
     * @param message 短语模板
     * @param listLuggage 行李号列表
     */
    public static void report(String tnb, String messageId, String message, List<LuggageVO> listLuggage) {
        if (TextUtils.isEmpty(tnb) || TextUtils.isEmpty(message)) {
            return;
        }

        ReportFindLuggageRequestVO reportFindLuggageRequestVO = new ReportFindLuggageRequestVO();
        reportFindLuggageRequestVO.setTNB(tnb);
        reportFindLuggageRequestVO.setMessageId(messageId);
        reportFindLuggageRequestVO.setMessage(message);
        if (listLuggage != null && !listLuggage.isEmpty()) {
            reportFindLuggageRequestVO.setListLuggage(listLuggage);
        }

        ReportFindLuggageRequest reportFindLuggageRequest = new ReportFindLuggageRequest();
        reportFindLuggageRequest.setReportFindLuggageRequestVO(reportFindLuggageRequestVO);

        HttpUtil.getInstance().sendRequest(reportFindLuggageRequest, MessageModel.FXLR, true);
    }

}
